//
//  UIBarButtonItem+CustomView.swift
//  ZNWeibo
//
//  Created by FunctionMaker on 2017/7/29.
//  Copyright © 2017年 FunctionMaker. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    convenience init(title: String, fontSize: CGFloat = 16, target: Any?, normalColor: UIColor = UIColor.darkGray, highlightedColor: UIColor = UIColor.orange, action: Selector, event: UIControlEvents, isBack: Bool = false) {
        let button: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: normalColor, highlightedColor: highlightedColor)
        button.addTarget(target, action: action, for: event)
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            
            button.setImage(UIImage(named: imageName), for: .normal)
            button.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            
            button.sizeToFit()
        }
        
        self.init(customView: button)
    }
}
